package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.service.INursingProjectService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 护理项目Controller
 *
 * @author ruoyi
 * @date 2025-05-18
 */
@RestController
@RequestMapping("/nursing/project")
@Api(tags = "护理项目管理接口", description = "用于护理项目的增删改查及导出功能")
public class NursingProjectController extends BaseController {

    @Autowired
    private INursingProjectService nursingProjectService;

    /**
     * 查询护理项目列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:list')")
    @GetMapping("/list")
    @ApiOperation("查询护理项目列表（支持分页）")
    public TableDataInfo<List<NursingProject>> list(
            @ApiParam(name = "nursingProject", value = "护理项目筛选条件对象，例如项目名称、状态等")
            NursingProject nursingProject) {
        startPage();
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        return getDataTable(list);
    }

    /**
     * 导出护理项目Excel
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:export')")
    @Log(title = "护理项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出护理项目数据到Excel文件")
    public void export(
            @ApiParam(name = "response", value = "HTTP响应对象，用于输出Excel文件流") HttpServletResponse response,
            @ApiParam(name = "nursingProject", value = "过滤条件，用于导出指定条件的护理项目") NursingProject nursingProject) {
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        ExcelUtil<NursingProject> util = new ExcelUtil<NursingProject>(NursingProject.class);
        util.exportExcel(response, list, "护理项目数据");
    }

    /**
     * 获取护理项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:query')")
    @GetMapping("/{id}")
    @ApiOperation("根据ID获取护理项目的详细信息")
    public R<NursingProject> getInfo(
            @ApiParam(name = "id", value = "要查询的护理项目唯一标识ID", required = true) @PathVariable("id") Long id) {
//        return success(nursingProjectService.selectNursingProjectById(id));
        return R.ok(nursingProjectService.selectNursingProjectById(id));
    }

    /**
     * 新增护理项目
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:add')")
    @Log(title = "护理项目", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增一个护理项目")
    public R add(
            @ApiParam(name = "nursingProject", value = "包含新护理项目信息的对象", required = true) @RequestBody NursingProject nursingProject) {
//        return toAjax();
        nursingProjectService.insertNursingProject(nursingProject);
        return R.ok();
    }

    /**
     * 修改护理项目
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:edit')")
    @Log(title = "护理项目", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改已有护理项目的信息")
    public R edit(
            @ApiParam(name = "nursingProject", value = "包含要修改的护理项目完整信息", required = true) @RequestBody NursingProject nursingProject) {
        nursingProjectService.updateNursingProject(nursingProject);
        return R.ok();
    }

    /**
     * 删除护理项目
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:remove')")
    @Log(title = "护理项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("根据ID数组删除护理项目")
    public R remove(
            @ApiParam(name = "ids", value = "要删除的护理项目ID数组", required = true) @PathVariable Long[] ids) {
        nursingProjectService.deleteNursingProjectByIds(ids);
        return R.ok();
    }
}